package org.hot100_1;

import org.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class leetcode45_1 {

    //将原来的TreeNode用前序遍历的方式存储到list中
    public void flatten(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        getList(root,list);
        TreeNode curr = root;

        for (int i = 1; i <list.size(); i++) {
            curr.left=null;
            curr.right=new TreeNode(list.get(i));
            curr =curr.right;
        }
    }

    private void getList(TreeNode root , List<Integer> list){
        if (root==null){
            return;
        }

        list.add(root.val);
        getList(root.left,list);
        getList(root.right,list);
    }
}
